/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.wpi.first.wpilibj.templates.tshirtcannon;

/**
 * Base class that both FillingState1 and FillingState2 extend.
 * @see FillingState1
 * @see FillingState2
 * @see TShirtCannon
 * @see TShirtCannonState
 */
class FillingState extends TShirtCannonState {
    private static final double kWaitForDumpValve = 0.5; //TODO: adjust value
    protected static final double kFillingTime = 2.0 + kWaitForDumpValve; //TODO: adjust value

    private static FillingState m_instance = new FillingState();

    private FillingState() {
    }
    /**
     * enter is called when the t-shirt cannon enters this state.
     * @param tsc The t-shirt cannon.
     */
    void enter(TShirtCannon tsc) {
        tsc.setCompressorState(true);
        tsc.setDumpValveState(false);
        tsc.setFireValve1State(false);
        tsc.setFireValve2State(false);
        tsc.setLightState(true);

        tsc.startTimer();
    }

    /**
     * update is called when something calls the t-shirt cannon's update
     * function and this is the current state.
     * @param tsc The t-shirt cannon.
     */
    void update(TShirtCannon tsc) {
        if (tsc.getTimerSeconds() > kWaitForDumpValve && !tsc.getFillValveState()) {
            tsc.setFillValveState(true);
        } else if(tsc.getTimerSeconds() > kFillingTime) {
            tsc.changeState(FilledState.instance());
        }

        super.update(tsc);
    }

    /**
     * exit is called when the t-shirt cannon enters this state.
     * @param tsc The t-shirt cannon.
     */
    void exit(TShirtCannon tsc) {
        tsc.stopTimer();
    }

    /**
     * getName is called to get the name of this state.
     * @return The name of this state.
     */
    String getName() {
        return "Filling";
    }

    /**
     * Returns the instance of this state.
     * @return The instance of this state.
     */
    static FillingState instance() {
        return m_instance;
    }
}
